

import 'package:flutter_getx/app/config/constant.dart';

class BaseEntity<T> {

  BaseEntity(this.code, this.msg, this.data, this.now);

  BaseEntity.fromJson(Map<String, dynamic> json) {
    code = json[Constant.code] as int?;
    msg = json[Constant.msg] as String?;
    if (json.containsKey(Constant.data) && json[Constant.data] != null) {
      data = _generateOBJ<T>(json[Constant.data] as Object);
    }
  }

  int? code;
  String? msg;
  T? data;
  int? now;


  T _generateOBJ<O>(Object json) {
    if (T.toString() == 'String') {
      return json.toString() as T;
    } else if (T.toString().startsWith('Map<')) {
      return json as T;
    } else {
      return json as T;
      /// List类型数据由fromJsonAsT判断处理
      //return JsonConvert.fromJsonAsT<T>(json);
    }
  }
}